package stackdemo;

import java.util.Arrays;

public class MyStack {
    public int[] array;
    public int usedSize;
    public MyStack(){
        this.array=new int[2];
    }
    public void push(int data){
        if(isFull()){
            this.array= Arrays.copyOf(array,2*array.length);
        }
        array[usedSize]=data;
        usedSize++;
    }
    public boolean isFull(){
        return usedSize==array.length;
    }
    public int pop(){
        if (isEmpty()){
            return -1;
        }
        usedSize--;
        return array[usedSize];
    }
    public boolean isEmpty(){
       return usedSize==0;
    }
    public int peek(){
        if(isEmpty()){
            return -1;
        }
        return array[usedSize-1];
    }
    public int size(){
        return usedSize;
    }
}
